package com.buba.controller;

import com.buba.pojo.DepartInfo;
import com.buba.pojo.Message;
import com.buba.service.DepartInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杨柳
 * @title DepartInfoController
 * @date 2024/4/23 8:32
 */
@RestController
@CrossOrigin(allowCredentials = "true"
        , originPatterns = "*")
public class DepartInfoController {
    @Autowired
    private DepartInfoService departInfoService;

    @GetMapping("/departInfo")
    public List<DepartInfo> selDepartInfo() {
        return departInfoService.selDepartInfo();
    }

    @DeleteMapping("/departInfo/{departId}")
    public Message delDepartInfo(@PathVariable Integer departId) {
        long count = departInfoService.delDepartInfo(departId);
        if (count == 0)
            return new Message(0, "删除错误");
        return new Message(1, "删除成功");
    }
    @PutMapping("/departInfo")
    public Message updDepartInfo(DepartInfo departInfo){
        long count = departInfoService.updDepartInfo(departInfo);
        if (count == 0)
            return new Message(0, "修改错误");
        return new Message(1, "修改成功");
    }

    @PostMapping("/departInfo")
    public Message addDepartInfo(DepartInfo departInfo){
        long count = departInfoService.addDepartInfo(departInfo);
        if (count == 0)
            return new Message(0, "添加错误");
        return new Message(1, "添加成功");
    }
}
